package dto;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import vo.employeesVO;
import vo.messengerVO;
import db.MySql;

public class ForgotDTO {

	private employeesVO evo = null;
	private messengerVO mvo = null;
	private Connection conn = null;

	//String saveDir = "C:/workspace/group/WebContent/images";

	public ForgotDTO() {
		this.conn = new MySql().getConn();
	}

	public messengerVO search_id(employeesVO evo) {
		this.evo = evo;
		
		mvo = new messengerVO();
		
		String sql = "select b.m_id from semyadmin.employees a "
				+ " join semyadmin.messenger b "
				+ " on a.e_number = b.e_number "
				+ " where a.e_number = ? and a.e_name = ? "
				+ " and a.e_contact = ?";
		
		try {
			
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setLong(1, evo.getE_number());
			pst.setString(2, evo.getE_name());
			pst.setInt(3, evo.getE_contact());
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				mvo.setM_id(rs.getString("m_id"));
			}
			rs.close();
			pst.close();
			conn.close();
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		return mvo;
	}

	public messengerVO search_pw(messengerVO mvo, employeesVO evo) {
		this.mvo = mvo;
		this.evo = evo;
		
		String sql = "select b.m_pw from semyadmin.employees a "
				+ " join semyadmin.messenger b "
				+ " on a.e_number = b.e_number "
				+ " where a.e_number = ? and b.m_id = ? "
				+ " and a.e_name = ? and a.e_contact = ? ";
		
		try {
			
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setLong(1, mvo.getE_number());
			pst.setString(2, mvo.getM_id());
			pst.setString(3, evo.getE_name());
			pst.setInt(4, evo.getE_contact());
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				mvo.setM_pw(rs.getString("m_pw"));
			}
			rs.close();
			pst.close();
			conn.close();
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		return mvo;
	}

	public void search_pw() {

	}
}
